﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using HHIDAL;
using HHDBUtility;//Please add references
namespace HHSQLServerDAL
{
	/// <summary>
	/// 数据访问类:Users
	/// </summary>
	public partial class Users:IUsers
	{
		public Users()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("ID", "Users");
        }

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from Users");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string  UserCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Users");
            strSql.Append(" where UserCode=@UserCode");
            SqlParameter[] parameters = {
					new SqlParameter("@UserCode", SqlDbType.NVarChar,50)
};
            parameters[0].Value = UserCode;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 判断密码是否存在
        /// </summary>
        public bool Exists(string UserNumber, string UserPassWord)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Users");
            strSql.Append(" where UserNumber=@UserNumber and UserPassWord=@UserPassWord");
            SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50),
                    new SqlParameter("@UserPassWord", SqlDbType.NVarChar,50)
};
            parameters[0].Value = UserNumber;
            parameters[1].Value = UserPassWord;
            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 判断登录帐号是否存
        /// </summary>
        public bool ExistsUserCode(string UserNumber, string UserCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Users");
            strSql.Append(" where UserNumber not in(@UserNumber) and UserCode=@UserCode");
            SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50),
                    new SqlParameter("@UserCode", SqlDbType.NVarChar,50)
};
            parameters[0].Value = UserNumber;
            parameters[1].Value = UserCode;
            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HHModel.Users model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Users(");
			strSql.Append("UserNumber,UserName,UserCode,UserPassWord,Signature,Roles,UserType,UserPicUrl,UserTel,UserEmail,UserAddress,RegState,OpenState,Sort,Creater,CreateTime,LastUpdater,LastUpdateTime)");
			strSql.Append(" values (");
			strSql.Append("@UserNumber,@UserName,@UserCode,@UserPassWord,@Signature,@Roles,@UserType,@UserPicUrl,@UserTel,@UserEmail,@UserAddress,@RegState,@OpenState,@Sort,@Creater,@CreateTime,@LastUpdater,@LastUpdateTime)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@UserName", SqlDbType.NVarChar,50),
					new SqlParameter("@UserCode", SqlDbType.NVarChar,50),
					new SqlParameter("@UserPassWord", SqlDbType.NVarChar,50),
					new SqlParameter("@Signature", SqlDbType.NVarChar,200),
					new SqlParameter("@Roles", SqlDbType.NVarChar,200),
					new SqlParameter("@UserType", SqlDbType.NVarChar,50),
					new SqlParameter("@UserPicUrl", SqlDbType.NVarChar,50),
					new SqlParameter("@UserTel", SqlDbType.NVarChar,50),
					new SqlParameter("@UserEmail", SqlDbType.NVarChar,50),
					new SqlParameter("@UserAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@RegState", SqlDbType.Int,4),
					new SqlParameter("@OpenState", SqlDbType.Int,4),
					new SqlParameter("@Sort", SqlDbType.Int,4),
					new SqlParameter("@Creater", SqlDbType.NVarChar,50),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@LastUpdater", SqlDbType.NVarChar,50),
					new SqlParameter("@LastUpdateTime", SqlDbType.DateTime)};
			parameters[0].Value = model.UserNumber;
			parameters[1].Value = model.UserName;
			parameters[2].Value = model.UserCode;
			parameters[3].Value = model.UserPassWord;
			parameters[4].Value = model.Signature;
			parameters[5].Value = model.Roles;
			parameters[6].Value = model.UserType;
			parameters[7].Value = model.UserPicUrl;
			parameters[8].Value = model.UserTel;
			parameters[9].Value = model.UserEmail;
			parameters[10].Value = model.UserAddress;
			parameters[11].Value = model.RegState;
			parameters[12].Value = model.OpenState;
			parameters[13].Value = model.Sort;
			parameters[14].Value = model.Creater;
			parameters[15].Value = model.CreateTime;
			parameters[16].Value = model.LastUpdater;
			parameters[17].Value = model.LastUpdateTime;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HHModel.Users model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Users set ");
			strSql.Append("UserNumber=@UserNumber,");
			strSql.Append("UserName=@UserName,");
			strSql.Append("UserCode=@UserCode,");
			strSql.Append("UserPassWord=@UserPassWord,");
			strSql.Append("Signature=@Signature,");
			strSql.Append("Roles=@Roles,");
			strSql.Append("UserType=@UserType,");
			strSql.Append("UserPicUrl=@UserPicUrl,");
			strSql.Append("UserTel=@UserTel,");
			strSql.Append("UserEmail=@UserEmail,");
			strSql.Append("UserAddress=@UserAddress,");
			strSql.Append("RegState=@RegState,");
			strSql.Append("OpenState=@OpenState,");
			strSql.Append("Sort=@Sort,");
			strSql.Append("Creater=@Creater,");
			strSql.Append("CreateTime=@CreateTime,");
			strSql.Append("LastUpdater=@LastUpdater,");
			strSql.Append("LastUpdateTime=@LastUpdateTime");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@UserName", SqlDbType.NVarChar,50),
					new SqlParameter("@UserCode", SqlDbType.NVarChar,50),
					new SqlParameter("@UserPassWord", SqlDbType.NVarChar,50),
					new SqlParameter("@Signature", SqlDbType.NVarChar,200),
					new SqlParameter("@Roles", SqlDbType.NVarChar,200),
					new SqlParameter("@UserType", SqlDbType.NVarChar,50),
					new SqlParameter("@UserPicUrl", SqlDbType.NVarChar,50),
					new SqlParameter("@UserTel", SqlDbType.NVarChar,50),
					new SqlParameter("@UserEmail", SqlDbType.NVarChar,50),
					new SqlParameter("@UserAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@RegState", SqlDbType.Int,4),
					new SqlParameter("@OpenState", SqlDbType.Int,4),
					new SqlParameter("@Sort", SqlDbType.Int,4),
					new SqlParameter("@Creater", SqlDbType.NVarChar,50),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@LastUpdater", SqlDbType.NVarChar,50),
					new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = model.UserNumber;
			parameters[1].Value = model.UserName;
			parameters[2].Value = model.UserCode;
			parameters[3].Value = model.UserPassWord;
			parameters[4].Value = model.Signature;
			parameters[5].Value = model.Roles;
			parameters[6].Value = model.UserType;
			parameters[7].Value = model.UserPicUrl;
			parameters[8].Value = model.UserTel;
			parameters[9].Value = model.UserEmail;
			parameters[10].Value = model.UserAddress;
			parameters[11].Value = model.RegState;
			parameters[12].Value = model.OpenState;
			parameters[13].Value = model.Sort;
			parameters[14].Value = model.Creater;
			parameters[15].Value = model.CreateTime;
			parameters[16].Value = model.LastUpdater;
			parameters[17].Value = model.LastUpdateTime;
			parameters[18].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
        /// <summary>
        /// 根据ID修改状态
        /// </summary>
        public bool UpdateStatusByID(int ID, int Status)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Users set ");
            strSql.Append("OpenState=@OpenState");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
					new SqlParameter("@OpenState", SqlDbType.Int,4),
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = Status;
            parameters[1].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
                return true;
            else
                return false;
        }
        //根据用户编号修改登录状态
        public void UpdateRegStateByUserNumber(string UserNumber, int RegState)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Users set ");
            strSql.Append("UserNumber=@UserNumber,");
            strSql.Append("RegState=@RegState");
            strSql.Append(" where UserNumber=@UserNumber");
            SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@RegState", SqlDbType.Int,4)};
            parameters[0].Value = UserNumber;
            parameters[1].Value = RegState;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        //修改用户信息但不修改密码
        public bool UpdateUserInfo(HHModel.Users model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Users set ");
            strSql.Append("UserNumber=@UserNumber,");
            strSql.Append("UserName=@UserName,");
            strSql.Append("UserCode=@UserCode,");
            strSql.Append("Signature=@Signature,");
            strSql.Append("Roles=@Roles,");
            strSql.Append("UserType=@UserType,");
            strSql.Append("UserPicUrl=@UserPicUrl,");
            strSql.Append("UserTel=@UserTel,");
            strSql.Append("UserEmail=@UserEmail,");
            strSql.Append("UserAddress=@UserAddress,");
            strSql.Append("RegState=@RegState,");
            strSql.Append("OpenState=@OpenState,");
            strSql.Append("Sort=@Sort,");
            strSql.Append("Creater=@Creater,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("LastUpdater=@LastUpdater,");
            strSql.Append("LastUpdateTime=@LastUpdateTime");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@UserName", SqlDbType.NVarChar,50),
					new SqlParameter("@UserCode", SqlDbType.NVarChar,50),
					new SqlParameter("@Signature", SqlDbType.NVarChar,200),
					new SqlParameter("@Roles", SqlDbType.NVarChar,200),
					new SqlParameter("@UserType", SqlDbType.NVarChar,50),
					new SqlParameter("@UserPicUrl", SqlDbType.NVarChar,50),
					new SqlParameter("@UserTel", SqlDbType.NVarChar,50),
					new SqlParameter("@UserEmail", SqlDbType.NVarChar,50),
					new SqlParameter("@UserAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@RegState", SqlDbType.Int,4),
					new SqlParameter("@OpenState", SqlDbType.Int,4),
					new SqlParameter("@Sort", SqlDbType.Int,4),
					new SqlParameter("@Creater", SqlDbType.NVarChar,50),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@LastUpdater", SqlDbType.NVarChar,50),
					new SqlParameter("@LastUpdateTime", SqlDbType.DateTime),
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = model.UserNumber;
            parameters[1].Value = model.UserName;
            parameters[2].Value = model.UserCode;
            parameters[3].Value = model.Signature;
            parameters[4].Value = model.Roles;
            parameters[5].Value = model.UserType;
            parameters[6].Value = model.UserPicUrl;
            parameters[7].Value = model.UserTel;
            parameters[8].Value = model.UserEmail;
            parameters[9].Value = model.UserAddress;
            parameters[10].Value = model.RegState;
            parameters[11].Value = model.OpenState;
            parameters[12].Value = model.Sort;
            parameters[13].Value = model.Creater;
            parameters[14].Value = model.CreateTime;
            parameters[15].Value = model.LastUpdater;
            parameters[16].Value = model.LastUpdateTime;
            parameters[17].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        //用户修改自己信息
        public bool UpdateByUserNumber(HHModel.Users model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Users set ");
            strSql.Append("UserName=@UserName,");
            strSql.Append("UserCode=@UserCode,");
            strSql.Append("Signature=@Signature,");
            strSql.Append("UserPicUrl=@UserPicUrl,");
            strSql.Append("UserTel=@UserTel,");
            strSql.Append("UserEmail=@UserEmail,");
            strSql.Append("UserAddress=@UserAddress");
            strSql.Append(" where UserNumber=@UserNumber");
            SqlParameter[] parameters = {
					new SqlParameter("@UserName", SqlDbType.NVarChar,50),
					new SqlParameter("@UserCode", SqlDbType.NVarChar,50),
					new SqlParameter("@Signature", SqlDbType.NVarChar,200),
					new SqlParameter("@UserPicUrl", SqlDbType.NVarChar,50),
					new SqlParameter("@UserTel", SqlDbType.NVarChar,50),
					new SqlParameter("@UserEmail", SqlDbType.NVarChar,50),
					new SqlParameter("@UserAddress", SqlDbType.NVarChar,50),
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.UserName;
            parameters[1].Value = model.UserCode;
            parameters[2].Value = model.Signature;
            parameters[3].Value = model.UserPicUrl;
            parameters[4].Value = model.UserTel;
            parameters[5].Value = model.UserEmail;
            parameters[6].Value = model.UserAddress;
            parameters[7].Value = model.UserNumber;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Users ");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Users ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HHModel.Users GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,UserNumber,UserName,UserCode,UserPassWord,Signature,Roles,UserType,UserPicUrl,UserTel,UserEmail,UserAddress,RegState,OpenState,Sort,Creater,CreateTime,LastUpdater,LastUpdateTime from Users ");
			strSql.Append(" where ID=@ID");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)
};
			parameters[0].Value = ID;

			HHModel.Users model=new HHModel.Users();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UserNumber"]!=null && ds.Tables[0].Rows[0]["UserNumber"].ToString()!="")
				{
					model.UserNumber=ds.Tables[0].Rows[0]["UserNumber"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserName"]!=null && ds.Tables[0].Rows[0]["UserName"].ToString()!="")
				{
					model.UserName=ds.Tables[0].Rows[0]["UserName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserCode"]!=null && ds.Tables[0].Rows[0]["UserCode"].ToString()!="")
				{
					model.UserCode=ds.Tables[0].Rows[0]["UserCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserPassWord"]!=null && ds.Tables[0].Rows[0]["UserPassWord"].ToString()!="")
				{
					model.UserPassWord=ds.Tables[0].Rows[0]["UserPassWord"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Signature"]!=null && ds.Tables[0].Rows[0]["Signature"].ToString()!="")
				{
					model.Signature=ds.Tables[0].Rows[0]["Signature"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Roles"]!=null && ds.Tables[0].Rows[0]["Roles"].ToString()!="")
				{
					model.Roles=ds.Tables[0].Rows[0]["Roles"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserType"]!=null && ds.Tables[0].Rows[0]["UserType"].ToString()!="")
				{
					model.UserType=ds.Tables[0].Rows[0]["UserType"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserPicUrl"]!=null && ds.Tables[0].Rows[0]["UserPicUrl"].ToString()!="")
				{
					model.UserPicUrl=ds.Tables[0].Rows[0]["UserPicUrl"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserTel"]!=null && ds.Tables[0].Rows[0]["UserTel"].ToString()!="")
				{
					model.UserTel=ds.Tables[0].Rows[0]["UserTel"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserEmail"]!=null && ds.Tables[0].Rows[0]["UserEmail"].ToString()!="")
				{
					model.UserEmail=ds.Tables[0].Rows[0]["UserEmail"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UserAddress"]!=null && ds.Tables[0].Rows[0]["UserAddress"].ToString()!="")
				{
					model.UserAddress=ds.Tables[0].Rows[0]["UserAddress"].ToString();
				}
				if(ds.Tables[0].Rows[0]["RegState"]!=null && ds.Tables[0].Rows[0]["RegState"].ToString()!="")
				{
					model.RegState=int.Parse(ds.Tables[0].Rows[0]["RegState"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OpenState"]!=null && ds.Tables[0].Rows[0]["OpenState"].ToString()!="")
				{
					model.OpenState=int.Parse(ds.Tables[0].Rows[0]["OpenState"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Sort"]!=null && ds.Tables[0].Rows[0]["Sort"].ToString()!="")
				{
					model.Sort=int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Creater"]!=null && ds.Tables[0].Rows[0]["Creater"].ToString()!="")
				{
					model.Creater=ds.Tables[0].Rows[0]["Creater"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreateTime"]!=null && ds.Tables[0].Rows[0]["CreateTime"].ToString()!="")
				{
					model.CreateTime=DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["LastUpdater"]!=null && ds.Tables[0].Rows[0]["LastUpdater"].ToString()!="")
				{
					model.LastUpdater=ds.Tables[0].Rows[0]["LastUpdater"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LastUpdateTime"]!=null && ds.Tables[0].Rows[0]["LastUpdateTime"].ToString()!="")
				{
					model.LastUpdateTime=DateTime.Parse(ds.Tables[0].Rows[0]["LastUpdateTime"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}
        ///</summary>
        /// 根据用户编号得到一个对象实体
        /// </summary>
        public HHModel.Users GetModelByUserNumber(string UserNumber)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,UserNumber,UserName,UserCode,UserPassWord,Signature,Roles,UserType,UserPicUrl,UserTel,UserEmail,UserAddress,RegState,OpenState,Sort,Creater,CreateTime,LastUpdater,LastUpdateTime from Users ");
            strSql.Append(" where UserNumber=@UserNumber");
            SqlParameter[] parameters = {
					new SqlParameter("@UserNumber", SqlDbType.NVarChar,50)
};
            parameters[0].Value = UserNumber;

            HHModel.Users model = new HHModel.Users();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserNumber"] != null && ds.Tables[0].Rows[0]["UserNumber"].ToString() != "")
                {
                    model.UserNumber = ds.Tables[0].Rows[0]["UserNumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserName"] != null && ds.Tables[0].Rows[0]["UserName"].ToString() != "")
                {
                    model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserCode"] != null && ds.Tables[0].Rows[0]["UserCode"].ToString() != "")
                {
                    model.UserCode = ds.Tables[0].Rows[0]["UserCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserPassWord"] != null && ds.Tables[0].Rows[0]["UserPassWord"].ToString() != "")
                {
                    model.UserPassWord = ds.Tables[0].Rows[0]["UserPassWord"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Signature"] != null && ds.Tables[0].Rows[0]["Signature"].ToString() != "")
                {
                    model.Signature = ds.Tables[0].Rows[0]["Signature"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Roles"] != null && ds.Tables[0].Rows[0]["Roles"].ToString() != "")
                {
                    model.Roles = ds.Tables[0].Rows[0]["Roles"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserType"] != null && ds.Tables[0].Rows[0]["UserType"].ToString() != "")
                {
                    model.UserType = ds.Tables[0].Rows[0]["UserType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserPicUrl"] != null && ds.Tables[0].Rows[0]["UserPicUrl"].ToString() != "")
                {
                    model.UserPicUrl = ds.Tables[0].Rows[0]["UserPicUrl"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserTel"] != null && ds.Tables[0].Rows[0]["UserTel"].ToString() != "")
                {
                    model.UserTel = ds.Tables[0].Rows[0]["UserTel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserEmail"] != null && ds.Tables[0].Rows[0]["UserEmail"].ToString() != "")
                {
                    model.UserEmail = ds.Tables[0].Rows[0]["UserEmail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserAddress"] != null && ds.Tables[0].Rows[0]["UserAddress"].ToString() != "")
                {
                    model.UserAddress = ds.Tables[0].Rows[0]["UserAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["RegState"] != null && ds.Tables[0].Rows[0]["RegState"].ToString() != "")
                {
                    model.RegState = int.Parse(ds.Tables[0].Rows[0]["RegState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OpenState"] != null && ds.Tables[0].Rows[0]["OpenState"].ToString() != "")
                {
                    model.OpenState = int.Parse(ds.Tables[0].Rows[0]["OpenState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Sort"] != null && ds.Tables[0].Rows[0]["Sort"].ToString() != "")
                {
                    model.Sort = int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Creater"] != null && ds.Tables[0].Rows[0]["Creater"].ToString() != "")
                {
                    model.Creater = ds.Tables[0].Rows[0]["Creater"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CreateTime"] != null && ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastUpdater"] != null && ds.Tables[0].Rows[0]["LastUpdater"].ToString() != "")
                {
                    model.LastUpdater = ds.Tables[0].Rows[0]["LastUpdater"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LastUpdateTime"] != null && ds.Tables[0].Rows[0]["LastUpdateTime"].ToString() != "")
                {
                    model.LastUpdateTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastUpdateTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 根据用户帐号和密码得到一个对象实体
        /// </summary>
        public HHModel.Users GetModel(string UserCode, string UserPassWord)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,UserNumber,UserName,UserCode,UserPassWord,Signature,Roles,UserType,UserPicUrl,UserTel,UserEmail,UserAddress,RegState,OpenState,Sort,Creater,CreateTime,LastUpdater,LastUpdateTime from Users ");
            strSql.Append(" where UserCode=@UserCode and UserPassWord=@UserPassWord and OpenState=1");
            SqlParameter[] parameters = {
					new SqlParameter("@UserCode", SqlDbType.NVarChar,50),
                    new SqlParameter("@UserPassWord", SqlDbType.NVarChar,50)
};
            parameters[0].Value = UserCode;
            parameters[1].Value = UserPassWord;
            HHModel.Users model = new HHModel.Users();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserNumber"] != null && ds.Tables[0].Rows[0]["UserNumber"].ToString() != "")
                {
                    model.UserNumber = ds.Tables[0].Rows[0]["UserNumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserName"] != null && ds.Tables[0].Rows[0]["UserName"].ToString() != "")
                {
                    model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserCode"] != null && ds.Tables[0].Rows[0]["UserCode"].ToString() != "")
                {
                    model.UserCode = ds.Tables[0].Rows[0]["UserCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserPassWord"] != null && ds.Tables[0].Rows[0]["UserPassWord"].ToString() != "")
                {
                    model.UserPassWord = ds.Tables[0].Rows[0]["UserPassWord"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Signature"] != null && ds.Tables[0].Rows[0]["Signature"].ToString() != "")
                {
                    model.Signature = ds.Tables[0].Rows[0]["Signature"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Roles"] != null && ds.Tables[0].Rows[0]["Roles"].ToString() != "")
                {
                    model.Roles = ds.Tables[0].Rows[0]["Roles"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserType"] != null && ds.Tables[0].Rows[0]["UserType"].ToString() != "")
                {
                    model.UserType = ds.Tables[0].Rows[0]["UserType"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserPicUrl"] != null && ds.Tables[0].Rows[0]["UserPicUrl"].ToString() != "")
                {
                    model.UserPicUrl = ds.Tables[0].Rows[0]["UserPicUrl"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserTel"] != null && ds.Tables[0].Rows[0]["UserTel"].ToString() != "")
                {
                    model.UserTel = ds.Tables[0].Rows[0]["UserTel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserEmail"] != null && ds.Tables[0].Rows[0]["UserEmail"].ToString() != "")
                {
                    model.UserEmail = ds.Tables[0].Rows[0]["UserEmail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserAddress"] != null && ds.Tables[0].Rows[0]["UserAddress"].ToString() != "")
                {
                    model.UserAddress = ds.Tables[0].Rows[0]["UserAddress"].ToString();
                }
                if (ds.Tables[0].Rows[0]["RegState"] != null && ds.Tables[0].Rows[0]["RegState"].ToString() != "")
                {
                    model.RegState = int.Parse(ds.Tables[0].Rows[0]["RegState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OpenState"] != null && ds.Tables[0].Rows[0]["OpenState"].ToString() != "")
                {
                    model.OpenState = int.Parse(ds.Tables[0].Rows[0]["OpenState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Sort"] != null && ds.Tables[0].Rows[0]["Sort"].ToString() != "")
                {
                    model.Sort = int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Creater"] != null && ds.Tables[0].Rows[0]["Creater"].ToString() != "")
                {
                    model.Creater = ds.Tables[0].Rows[0]["Creater"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CreateTime"] != null && ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastUpdater"] != null && ds.Tables[0].Rows[0]["LastUpdater"].ToString() != "")
                {
                    model.LastUpdater = ds.Tables[0].Rows[0]["LastUpdater"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LastUpdateTime"] != null && ds.Tables[0].Rows[0]["LastUpdateTime"].ToString() != "")
                {
                    model.LastUpdateTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastUpdateTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,UserNumber,UserName,UserCode,UserPassWord,Signature,Roles,UserType,UserPicUrl,UserTel,UserEmail,UserAddress,RegState,OpenState,Sort,Creater,CreateTime,LastUpdater,LastUpdateTime ");
			strSql.Append(" FROM Users ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,UserNumber,UserName,UserCode,UserPassWord,Signature,Roles,UserType,UserPicUrl,UserTel,UserEmail,UserAddress,RegState,OpenState,Sort,Creater,CreateTime,LastUpdater,LastUpdateTime ");
			strSql.Append(" FROM Users ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "Users";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method


        public bool UpdatePwdByUserNumber(string UserNumber,string pwd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Users set UserPassWord=@pwd");
            strSql.Append(" where UserNumber=@UserNumber");
            SqlParameter[] parameters = {
					new SqlParameter("@pwd", SqlDbType.NVarChar,50),
                    new SqlParameter("@UserNumber",SqlDbType.NVarChar,50)
};
            parameters[0].Value = pwd;
            parameters[1].Value = UserNumber;
           int rows= DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
           if (rows > 0)
               return true;
           else
               return false;
        }
    }
}

